<template>
  <h1>El组件-表格</h1>
  <el-table :data="arr" style="width: 600px;margin: 0 auto;" border="1px">
    <el-table-column label="编号" type="index" width="88" align="center"></el-table-column>
    <el-table-column label="姓名" prop="name"></el-table-column>
    <el-table-column label="薪资" prop="salary"></el-table-column>
    <el-table-column label="职位" prop="job"></el-table-column>
    <el-table-column label="操作">
      <!--自定义列模板template-->
      <!--      #default 定义一个插槽(slot)名为default
      scope就是一个对象,该对象是一个范围对象,可以保存上下文数据-->
      <template #default="scope">
<!--        scoped对象保存了当前行数据的索引$index(从0开始)与当前的完整对象scope.row-->
        <el-button type="danger" @click="del(scope.$index,scope.row)">删除</el-button>
      </template>
    </el-table-column>
  </el-table>
</template>

<script setup>
import {ref} from "vue";

const arr = ref([
  {name: '张三', salary: 3000, job: '饲养员'},
  {name: '李四', salary: 5000, job: '护林员'},
  {name: '王五', salary: 6000, job: '保洁员'},
  {name: '赵六', salary: 7000, job: '销售员'}
])
//定义删除员工的方法
const del = (index, emp) => {
  if (confirm('您确认要删除' + emp.name + '吗?')) {
    arr.value.splice(index, 1)
  }
}

</script>

<style scoped>

</style>